package com.jsoup;

import java.io.IOException;   
import java.io.UnsupportedEncodingException;   
import java.net.MalformedURLException;   
  
import org.jsoup.Jsoup;   
import org.jsoup.nodes.Document;   
  
  
/**  
* 获取56网视频  
* @author honny.huang  
* 2011-4-1  
* http://hi.juziku.com/sunlightcs/  
*/  
public class JsoupParse56 {   
    private static String URL = "http://www.56.com/u64/v_NTkzMDEzMTc.html";   
       
    public static void main(String[] args) throws Exception{   
           
        Document doc = getURLContent();   
        String content = doc.html();   
           
        /**  
         * 获取视频缩略图  
         */  
        int begin = content.indexOf("\"img\":\"");   
        content = content.substring(begin+7, begin+200);   
        int end = content.indexOf("\"};");   
        String pic = content.substring(0, end).trim();   
        pic = pic.replaceAll("\\\\", "");   
        System.out.println("视频缩略图："+pic);   
           
           
        /**  
         * 获取视频地址  
         */  
        String flash = "http://player.56.com" + URL.substring(URL.lastIndexOf("/"),    
                URL.lastIndexOf(".html")) + ".swf";   
        System.out.println("视频地址："+flash);   
           
    }   
  
       
    /**  
     * 获取56网页的内容  
     */  
    private static Document getURLContent() throws MalformedURLException,    
        IOException, UnsupportedEncodingException {   
        Document doc = Jsoup.connect(URL)   
          .data("query", "Java")   
          .userAgent("Mozilla")   
          .cookie("auth", "token")   
          .timeout(6000)   
          .post();   
        return doc;   
    }   
  
}  

